package com.csy.rabbit.merchant.controller;

import com.csy.rabbit.commit.result.Result;
import com.csy.rabbit.merchant.entity.Shop;
import com.csy.rabbit.merchant.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 店铺表 前端控制器
 * </p>
 *
 * @author csy
 * @since 2022-12-09
 */
@RestController
@Slf4j
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private ShopService shopService;

    @PostMapping("")
    public Result<Object> add(@RequestBody Shop shop){
        log.info("{}",shop);
        //shopName不能为空
        if(shop.getShopName()==null){
            return Result.error("店铺名不能为空");
        }
        //merchantId不能为空
        if(shop.getMerchantId()==null){
            return Result.error("商家id不能为空");
        }
        boolean result = shopService.save(shop);

        if(result){
            return Result.success("添加店铺成功");
        }
        return Result.error("未知错误");
    }

}
